document.addEventListener('DOMContentLoaded', () => {
    const publishForm = document.getElementById('publishForm');
    const successMessage = document.getElementById('successMessage');
    const errorMessage = document.getElementById('errorMessage');

    // 检查登录状态
    if (!localStorage.getItem('isLoggedIn')) {
        window.location.href = 'login.html';
        return;
    }

    publishForm.addEventListener('submit', (e) => {
        e.preventDefault();
        
        const title = document.getElementById('title').value;
        const content = document.getElementById('content').value;
        const publishTime = new Date().toLocaleString();

        // 这里应该发送到后端保存，这里仅作演示
        const news = {
            id: Date.now(), // 使用时间戳作为临时ID
            title,
            content,
            publishTime
        };

        // 模拟保存成功
        successMessage.style.display = 'block';
        setTimeout(() => {
            successMessage.style.display = 'none';
            publishForm.reset();
        }, 3000);
    });
}); 